<template>
  <el-card>
    <el-form inline style="margin-top: 20px; box-sizing: border-box">
      <el-form-item label="一级分类" style="width: 350px">
        <el-select :disabled="scene" v-model="categoryStore.c1Id" @change="handler">
          <el-option
            v-for="(c1, index) in categoryStore.c1Arr"
            :key="c1.id"
            :label="c1.category_title"
            :value="c1.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类" style="width: 350px">
        <el-select :disabled="scene" v-model="categoryStore.c2Id" @change="handler1">
          <el-option
            v-for="(c2, index) in categoryStore.c2Arr"
            :key="c2.id"
            :label="c2.category_title"
            :value="c2.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类" style="width: 350px">
        <el-select :disabled="scene" v-model="categoryStore.c3Id">
          <el-option
            v-for="(c3, index) in categoryStore.c3Arr"
            :key="c3.id"
            :label="c3.category_title"
            :value="c3.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="warning" icon="Refresh" @click="resetAll" :disabled="scene"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup lang="ts">
import { onMounted } from "vue";
import useCategoryStore from "@/store/modules/category";
let categoryStore = useCategoryStore();

onMounted(() => {
  getC1();
});

const getC1 = () => {
  categoryStore.getC1();
};

const handler = () => {
  categoryStore.c2Id = "";
  categoryStore.c3Arr = [];
  categoryStore.c3Id = "";
  categoryStore.getC2();
};

const handler1 = () => {
  categoryStore.c3Id = "";
  categoryStore.getC3();
};

const resetAll = () => {
  console.log("重置");
  categoryStore.c1Id = "";
  categoryStore.c2Id = "";
  categoryStore.c3Id = "";
  categoryStore.c2Arr = [];
  categoryStore.c3Arr = [];
};

defineProps(["scene"]);
</script>

<style lang="scss" scoped></style>
